<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.net.URLEncoder"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>出场</title>
</head>
<body>
	车场ID：
	<input type="text" id="parkLotCustomerId" />
	</br>车场UUID：
	<input type="text" id="uuid" />
	</br>车牌号码：
	<input type="text" id="carNo" />
	</br>金额￥（单位元）：
	<input type="text" id="charge" />
	</br>
	<button id="carOutBtn">车辆出场</button>
	</br>

	<div id="testDiv"></div>
</body>
<div id="confirDiv" style="display: none; padding: 10px">
	<table>
		<tr>
			<td>msg:</td>
			<td id="msgDiv"></td>
		</tr>
		<tr>
			<td>车场ID：</td>
			<td id="parkLotCustomerIdDiv"></td>
		</tr>
		<tr>
			<td>车场UUID：</td>
			<td id="uuidDiv"></td>
		</tr>
		<tr>
			<td>停车信息ID：</td>
			<td id="parkInfoIdDiv"></td>
		</tr>
	</table>
	</br>
</div>

<script src="${ctx}/static/plug/layer/layer.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#carOutBtn").click(function() {
			$("#testDiv").html("");
			$("#msgDiv").html("");
			$("#parkLotCustomerIdDiv").html("");
			$("#uuidDiv").html("");
			$("#parkInfoIdDiv").html("");

			var parkLotCustomerId = $("#parkLotCustomerId").val();
			var uuid = $("#uuid").val();
			var carNo = $("#carNo").val();
			var inTime = new Date().format('yyyy-MM-dd h:m:s');
			var outTime = new Date().format('yyyy-MM-dd h:m:s');
			var charge = $("#charge").val();
			if (parkLotCustomerId && uuid && carNo && inTime && outTime && charge) {
				var paraObj = {
					"parkLotCustomerId" : parkLotCustomerId,
					"uuid" : uuid,
					"carNo" : carNo,
					"inTime" : inTime,
					"outTime" : outTime,
					"charge" : charge * 10
				};
				$.post("${ctx}/parkInfo/park", paraObj, function(obj) {
					dealWithRespone(parkLotCustomerId, uuid, obj);
				});
			} else {
				showTips("warn","输入完整参数");
			}
		});

		function confirmGetMoney(parkLotCustomerId, uuid, parkInfoId, chargeType, layIndex) {
			$("#testDiv").html("");
			$("#msgDiv").html("");

			var paraObj = {
				"parkLotCustomerId" : parkLotCustomerId,
				"uuid" : uuid,
				"parkInfoId" : parkInfoId,
				"chargeType" : chargeType
			};

			$.ajax({
				type : "post",
				url : "${ctx}/parkInfo/confirmReceiveMoney",
				data : paraObj,
				async : false,//取消异步  
				success : function(obj) {
					layer.alert(obj.resultMsg, function(index) {
						layer.close(index);
						$("#testDiv").html(JSON.stringify(obj));
						$("#msgDiv").html(obj.resultMsg);
						if (obj.resultCode == "20000") {
							layer.close(layIndex);
						} else if (obj.resultCode == "50001") {
							layer.close(layIndex);
						} else if (obj.resultCode == "30001") {
							layer.close(layIndex);
						} else {

						}
					});
				}
			});
		}

		function dealWithRespone(parkLotCustomerId, uuid, obj) {
			$("#testDiv").html(JSON.stringify(obj));
			if (obj.resultCode) {
				layer.alert(obj.resultMsg, function(index) {
					layer.close(index);
					$("#testDiv").html(JSON.stringify(obj));
					$("#msgDiv").html(obj.resultMsg);
					if (obj.resultCode == "20000") {

					} else if (obj.resultCode == "50001") {

					} else if (obj.resultCode == "30001") {

					} else {
						$("#msgDiv").html(obj.resultMsg);
						$("#parkLotCustomerIdDiv").html(parkLotCustomerId);
						$("#uuidDiv").html(uuid);
						$("#parkInfoIdDiv").html(obj.parkInfoId);
						layer.open({
							type : 1,
							closeBtn : 0,
							content : $('#confirDiv'),
							btn : [ '现金支付', '平台代扣' ],
							yes : function(index, layero) {
								confirmGetMoney(parkLotCustomerId, uuid, obj.parkInfoId, 1, index);
							},
							btn2 : function(index, layero) {
								confirmGetMoney(parkLotCustomerId, uuid, obj.parkInfoId, 2, index);
								return false;
							}
						});
					}
				});
			}
		}
	});
</script>
</html>